/**
 * 从food_data.json中移除taurine_mg, taurine_rich, pantothenic_acid_mg, pantothenic_acid_rich字段
 * 因为这些营养素应该放在other_nutrients中
 */

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// 读取food_data.json
const foodDataPath = path.join(__dirname, '../database/food_data.json');
const foodData = JSON.parse(fs.readFileSync(foodDataPath, 'utf8'));

console.log(`读取到 ${foodData.length} 种食物`);

// 移除字段
let removedCount = 0;
foodData.forEach(food => {
  let hasFields = false;
  
  if ('taurine_mg' in food) {
    delete food.taurine_mg;
    hasFields = true;
  }
  if ('taurine_rich' in food) {
    delete food.taurine_rich;
    hasFields = true;
  }
  if ('pantothenic_acid_mg' in food) {
    delete food.pantothenic_acid_mg;
    hasFields = true;
  }
  if ('pantothenic_acid_rich' in food) {
    delete food.pantothenic_acid_rich;
    hasFields = true;
  }
  
  if (hasFields) {
    removedCount++;
  }
});

console.log(`✅ 已从 ${removedCount} 个食物中移除牛磺酸和泛酸字段`);

// 写回文件
fs.writeFileSync(foodDataPath, JSON.stringify(foodData, null, 4), 'utf8');
console.log('✅ 已保存到 database/food_data.json');

